/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.edu.upc.sad.controller;
import com.google.gson.Gson;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.TooManyListenersException;
import javax.servlet.http.HttpSession;
import pe.edu.upc.sad.dao.EmpresaAreaDao;
import pe.edu.upc.sad.dao.EmpresaAreaDaoImpl;
import pe.edu.upc.sad.dao.ReservaDao;
import pe.edu.upc.sad.dao.ReservaDaoImpl;
import pe.edu.upc.sad.dao.TipoAreaDao;
import pe.edu.upc.sad.dao.TipoAreaDaoImpl;
import pe.edu.upc.sad.model.EmpresaArea;
import pe.edu.upc.sad.model.MensajeResultado;
import pe.edu.upc.sad.model.Reserva;
import pe.edu.upc.sad.model.TipoArea;
import pe.edu.upc.sad.util.Conexion;
import pe.edu.upc.sad.util.ToolSql;
/**
 *
 * @author HP
 */
public class ListarConfirmarReserva extends HttpServlet {

     ReservaDao tarea = new ReservaDaoImpl();

     @Override
    public void doPost(HttpServletRequest request,
            HttpServletResponse response) throws ServletException,
            IOException {
         Gson gson = new Gson();

         List<Reserva> lstArea = null ;
        try
        {
             String estado=(request.getParameter("estado") != null) ?  request.getParameter("estado").toString()  : "";
             String idempresa=(request.getParameter("idempresa") != null) ?  request.getParameter("idempresa").toString()  : "";
             int id_estado=(estado.toString().equals("")) ?   0 : Integer.parseInt(estado);


             lstArea = tarea.getListReservaByEstado(id_estado,idempresa);
            String json = "{'Reservas':";
            json += gson.toJson(lstArea) + "}";// gson.toJson(obj);

            //response.setContentType("text/plain");
            response.setContentType("text/x-json;charset=UTF-8");
            response.setHeader("Cache-Control", "no-cache");
            //response.setContentLength(message.length());
            PrintWriter out = response.getWriter();
            out.println(json);

            out.close();
            out.flush();

        }catch(Exception e)
        {

            lstArea = new ArrayList<Reserva>();
            String json = "{'Reservas':";
            json += gson.toJson(lstArea)  + "}";

            //response.setContentType("text/plain");
            response.setContentType("text/x-json;charset=UTF-8");
            response.setHeader("Cache-Control", "no-cache");
            //response.setContentLength(message.length());
            PrintWriter out = response.getWriter();
            out.println(json);

            out.close();
            out.flush();
        }
    }

    @Override
    public void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException,
            IOException {

    }
}
